package com.yxuan.springboot.service.impl;

import com.yxuan.springboot.mapper.AgentsMapper;
import com.yxuan.springboot.model.mysqlModels.TdAndYdKPI;
import com.yxuan.springboot.model.mysqlModels.agentKPI;
import com.yxuan.springboot.util.IdUtil;
import com.yxuan.springboot.util.MD5Util;
import com.yxuan.springboot.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yxuan.springboot.model.Agents;
import com.yxuan.springboot.service.AgentsService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 
 * @author zchao
 *    Agents业务层实现类
 * @date 2024-05-24 16:31:04
 */
@Slf4j
@Service
@Transactional
public class AgentsServiceImpl extends BaseServiceImpl<Agents> implements AgentsService {

    @Autowired
    private AgentsMapper agentsMapper;

    @Override
    public Result agentLogin(String aphonenumber, String apassword) throws Exception {

        if(aphonenumber==null||aphonenumber.trim().isEmpty()){
            return new Result(201,"手机号不能为空");
        }
        Agents A = new Agents();
        A.setAphonenumber(aphonenumber);
        Agents targetA = agentsMapper.queryObjectByPramas(A);
        if(targetA==null){
            //找不到用户
            return new Result(A,201,"找不到用户，登录失败");
        }else {
            //登录
            A.setApassword(apassword);
            Agents AL = agentsMapper.queryObjectByPramas(A);
            if (AL==null){
                return new Result(201,"密码错误");
            }
            return new Result(AL,200,"登录成功");
        }
    }

    /*
    * 查看业绩
    * */
    @Override
    public Result getKPI(String agentId) throws Exception {

        List<agentKPI> dailyKPI = agentsMapper.getDailyKPI(agentId);

        return new Result(dailyKPI,200);
    }

    /*
    * 查看今天与昨天业绩
    * */
    @Override
    public Result getTDANDYDKPI(String agentId) throws Exception {
        TdAndYdKPI tdAndYdKPI = agentsMapper.getTdAndYdKPI(agentId);
        log.info("===================================="+tdAndYdKPI);
        return new Result(tdAndYdKPI,200);
    }


}
